<?php

namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class OnepageController extends AdminbaseController {

    function _initialize() {
        parent::_initialize();
        $this->onepage_model = D("Common/Onepage");
    }

    /**
     * 单页面
     */
    function index() {
        $select_list=D("Onepage")->order("create_time desc")->select();
         $this->assign("select_list",$select_list);       
        $this->display();
    }

    /**
     * 添加单页面
     */
    public function add() {
        if (IS_POST) {
            if ($this->onepage_model->create()) {
                if($this->onepage_model->add()){
                    $this->success("保存成功");
                }else{
                    $this->error("保存失败");
                }
            }else{
                $this->error($this->onepage_model->getError());
            }
        }
        $this->display();
    }
    public function edit(){
          $id=I("id");
          if (IS_POST) {
            if ($this->onepage_model->create()) {
                if($this->onepage_model->save()){
                    $this->success("保存成功");
                }else{
                    $this->error("保存失败");
                }
            }else{
                $this->error($this->onepage_model->getError());
            }
        }
        $info=$this->onepage_model->where(array("id"=>$id))->find();
        $this->assign("info",$info);
        $this->display("add");
    }
    public function del(){
        $id=I("id");
        if($this->onepage_model->where(array('id'=>$id))->delete()){
            $this->success("已删除");
        }else{
            $this->error("删除失败");
        }
    }

}
